unit GMedParkRusis;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, GForm, cxGraphics, cxPropertiesStore, dxBarExtItems, dxBar,
  cxClasses, ActnList, dxStatusBar, cxControls, cxPC, cxStyles, cxCustomData,
  cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridCustomView,
  cxGrid, cxNavigator, cxDBNavigator, cxContainer, cxGroupBox;

type
  TfMedParkRusis = class(TGamaForm)
    tsSarasas: TcxTabSheet;
    dbgSarasas: TcxGrid;
    dbgSarasasDBTableView: TcxGridDBTableView;
    dbgSarasasLevel1: TcxGridLevel;
    cxGroupBox1: TcxGroupBox;
    dbnNav: TcxDBNavigator;
    dbgSarasasDBTableViewrusis: TcxGridDBColumn;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    procedure LentelesOn;
    procedure LentelesOff;
    //
    procedure MainBeforeInserOrEdit(DataSet: TDataSet);
    procedure MainBeforePost(DataSet: TDataSet);
    procedure MainAfterPostOrDelete(DataSet: TDataSet);
    procedure MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
    procedure MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
    procedure MainNewRecord(DataSet: TDataSet);
  public
    { Public declarations }
    procedure RefreshTables; override;
  end;

var
  fMedParkRusis: TfMedParkRusis;

implementation

{$R *.dfm}

uses
  bendri, med_dm, Tools;

procedure TfMedParkRusis.LentelesOn;
begin
  with dmMed do begin
    tbMedParkRusis.BeforeInsert  := self.MainBeforeInserOrEdit;
    tbMedParkRusis.BeforeEdit    := self.MainBeforeInserOrEdit;
    tbMedParkRusis.BeforePost    := self.MainBeforePost;
    tbMedParkRusis.AfterPost     := self.MainAfterPostOrDelete;
    tbMedParkRusis.AfterDelete   := self.MainAfterPostOrDelete;
    tbMedParkRusis.AfterCancel   := self.MainAfterPostOrDeleteOrCancel;
    //tbMedParkRusis.OnPostError   := self.MainPostError;
    tbMedParkRusis.OnNewRecord   := self.MainNewRecord;
  end;
end;

procedure TfMedParkRusis.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  LentelesOff;
end;

procedure TfMedParkRusis.FormShow(Sender: TObject);
begin
  inherited;
  LentelesOn;
end;

procedure TfMedParkRusis.LentelesOff;
begin
  with dmMed do begin
    tbMedParkRusis.BeforeInsert  := nil;
    tbMedParkRusis.BeforeEdit    := nil;
    tbMedParkRusis.BeforePost    := nil;
    tbMedParkRusis.AfterPost     := nil;
    tbMedParkRusis.AfterDelete   := nil;
    tbMedParkRusis.AfterCancel   := nil;
    //tbMedRastKub.OnPostError   := nil;
    tbMedParkRusis.OnNewRecord   := nil;
  end;
end;

procedure TfMedParkRusis.MainBeforePost(DataSet: TDataSet);
begin
  //MessageText := '';
  //dmBendras.RandomIDBeforePost(DataSet);
end;

procedure TfMedParkRusis.MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
begin
  //dmBendras.RandomIDPostError(DataSet, E, Action);
end;

procedure TfMedParkRusis.MainNewRecord(DataSet: TDataSet);
begin
  //
end;

procedure TfMedParkRusis.MainAfterPostOrDelete(DataSet: TDataSet);
begin
  dmBendras.ApplyUpdatesAfterPostOrDelete(DataSet);
  MainAfterPostOrDeleteOrCancel(DataSet);
  bRefreshTables := true;
end;

procedure TfMedParkRusis.MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, false );
end;

procedure TfMedParkRusis.MainBeforeInserOrEdit(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, true);
end;

procedure TfMedParkRusis.RefreshTables;
begin
  if bRefreshTables then begin
    bRefreshTables := false;
    //dmAlga.tbIssilavLookup.Refresh;
  end
end;

end.
